Imports Microsoft.VisualBasic
Imports System
Imports System.WEB
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDb
Public Class cTbTemplates
    Dim mstrConnString As String

    Public Function GetFelder(ByVal TNr As Integer, Optional ByVal pWhere As String = "") As DataView
        Dim myConn As New OleDbConnection(mstrConnString)
        myConn.Open()

        ' Kommando-Objekt vorbereiten
        Dim cmd As New OleDbCommand()
        cmd.Connection = myConn
        ' Adapter-Objekt vorbereiten
        Dim myAdapter As New OleDbDataAdapter()
        myAdapter.SelectCommand = cmd
        ' DataSet-Objekt vorbereiten
        Dim myDS As New DataSet()

        ' Tabelle "Pages" einlesen
        Dim Sql As String
        If pWhere <> "" Then
            Sql = "SELECT TOP 1 * FROM tbl_content_templates WHERE " & pWhere
        Else
            Sql = "SELECT TOP 1 * FROM tbl_content_templates WHERE Cnr = " & TNr
        End If
        cmd.CommandText = Sql
        myAdapter.Fill(myDS, "Pages")

        GetFelder = New DataView(myDS.Tables("Pages"))
        myDS.Dispose()
        myConn.Close()
    End Function

    Public Sub Update(ByVal TNr As Integer, Optional ByVal Titel As String = Nothing, _
                                                    Optional ByVal Content As String = Nothing, _
                                                    Optional ByVal homepage As Integer = Nothing)
        Dim Sql As String = ""
        If Not Titel = Nothing Then Sql += ", Titel = '" & Titel & "'"
        If Not Content = Nothing Then Sql += ", Content = '" & Content & "'"
        If Not homepage = Nothing Then Sql += ", homepage = " & homepage
        If Sql.Length > 0 Then Sql = "UPDATE tbl_content_templates SET " & Sql.Substring(2)
        Sql += " WHERE cnr = " & TNr
        Dim myConn As New OleDbConnection(mstrConnString)
        Dim Cmd As New OleDbCommand(Sql, myConn)
        myConn.Open()
        Cmd.ExecuteReader()
        myConn.Close()
    End Sub

    Public Sub Delete(ByVal TNr As Integer)
        Dim strSQL As String = "DELETE * FROM tbl_content_templates WHERE cnr = " & TNr & ";"
        Dim dconn As New OleDbConnection(mstrConnString)
        Dim iCmd As New OleDbCommand(strSQL, dconn)
        dconn.Open()
        iCmd.ExecuteReader()
        dconn.Close()
    End Sub

    Public Sub Insert(Optional ByVal Titel As String = Nothing, _
                        Optional ByVal Content As String = Nothing, _
                        Optional ByVal homepage As Integer = Nothing)
        Dim F As String = ""
        Dim W As String = ""
        Dim Sql As String = ""
        If Not Titel = Nothing Then F += ",Titel" : W += ",'" & Titel & "'"
        If Not Content = Nothing Then F += ",Content" : W += ",'" & Content & "'"
        If Not homepage = Nothing Then F += ",homepage" : W += ",'" & homepage & "'"
        If F.Length > 0 Then
            Sql = "INSERT INTO tbl_content_templates (" & F.Substring(1) & ") VALUES(" & W.Substring(1) & ")"
            Dim myConn As New OleDbConnection(mstrConnString)
            Dim Cmd As New OleDbCommand(Sql, myConn)
            myConn.Open()
            Cmd.ExecuteReader()
            myConn.Close()
        End If
    End Sub

    Public Sub New(ByVal strConnString As String)
        mstrConnString = strConnString
    End Sub
End Class



